{	Problem: http://codeforces.ru/problemset/problem/8/A
	Verdict: Accepted
}
uses sysutils;
var s,sr,p,r:string; t,f:boolean; i,k:longint;
begin
readln(s);
readln(p);
readln(r);
sr:='';
k:=length(S);
for i:=1 to k do sr:=sr+s[k-i+1];
k:=pos(p,s);
t:=false;
f:=false;
if k<>0 then begin
  delete(s,1,k+length(p)-1);
  if pos(r,s)<>0 then t:=true;
end;
k:=pos(p,sr);
if k<>0 then begin
  delete(sr,1,k+length(p)-1);
  if pos(r,sr)<>0 then f:=true;
end;
if t and f then write('both') else
if t then write('forward') else
if f then write('backward') else write('fantasy');
end.